import FlexSearch from "flexsearch";

const index = new FlexSearch.Document({
  document: {
    id: "id",
    index: ["content"],
    store: true,
  },
  language: "en",
  stemmer: {
    中南林业科技大学: "林科大",
    run: "runing",
  },
  // encode: (text) => {
  //   text.split(/\t+/g);
  // },
  filter: ["is", "啊"],
  // filter: (words) => {
  //   console.log("filter words:", words);
  //   return false;
  // },
  // encode: (str) => cut(str),
});

index.add({ id: 0, content: "hello i am Jack. i runing" });
index.add({ id: 1, content: "this is best tester, jack" });

index.export((key, data) => {
  console.log("导出:", key, data);
});
console.log("`jack`搜索结果", index.search("jack", { enrich: true }));
console.log(
  "`jack`搜索结果",
  index.search("jack", { pluck: "content", enrich: true })
);
console.log("`tester`搜索结果", index.search("tester"));
console.log("`is`搜索结果", index.search("is"));
console.log("`this`搜索结果", index.search("this"));
console.log("`run`搜索结果", index.search("run"));
